package com.mt.api.modules.controller;

import com.mt.log.annotation.Log;
import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import com.mt.api.modules.service.AppSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;


/**
 * @author plover
 * @date 2020-07-06
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "sku管理")
@RequestMapping("/app/sku")
public class AppSkuController {

    private final AppSkuService skuService;

    @GetMapping("/list")
    @Log("查询品牌下的所有sku")
    @ApiOperation(value = "", notes = "获取品牌下sku列表", httpMethod = "GET")
    public WebResponse listByBrandId() {
        return skuService.listByBrandId();
    }

    @GetMapping("/getAllCargoNo")
    @Log("查询品牌下的所有cargoNo")
    @ApiOperation(value = "", notes = "获取品牌下所有款号", httpMethod = "GET")
    public WebResponse getAllCargoNo(String cargoNo) {
        return skuService.getAllCargoNo(cargoNo);
    }


    @GetMapping("/getByCargoId")
    @Log("通过款号查询对应的sku信息")
    @ApiOperation(value = "", notes = "通过款号查询对应的sku信息", httpMethod = "GET")
    public WebResponse getByCargoId(Integer cargoId) {
        if (Objects.isNull(cargoId)) {
            return WebResponseUtils.errorParam("cargoId不能为空");
        }
        return skuService.getByCargoId(cargoId);
    }


    @GetMapping("/getByCargoNoGroupColor")
    @Log("通过款号查询对应的size、color")
    @ApiOperation(value = "", notes = "根据款号查询sku列表-根据颜色分组", httpMethod = "GET")
    public WebResponse getByCargoNoGroupColor(String cargoNo) {
        if (StringUtils.isEmpty(cargoNo)) {
            return WebResponseUtils.errorParam("款号不能为空");
        }
        return skuService.getByCargoNoGroupColor(cargoNo);
    }
}